﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Security;
using System.Web;
using System.Web.Mvc;
using UnionManager.Models;
using UnionManager.Controllers;
using UnionManager.ViewModels;
using UnionManager.Infrastructure;

namespace UnionManager.Controllers.UnionModule
{
    public class ArticleController : BaseController
    {
        //
        // GET: /Article/
        Article db_art = (Article)DAOFactory.getDAO("Article");
        
        public ActionResult CreateArticle()
        {            
            return View();
        }

        [HttpPost]
        public ActionResult SaveArticle(ArticleModel values)
        {
            BAIVIET art = new BAIVIET();
            art.TieuDe = values.title;
            art.NoiDungHienThi = Server.HtmlEncode(values.content);            
            art.Id_ThuMuc = Int32.Parse(values.catagory);

            //Bo sung sau khi co phan quyen
            art.Id_TacGia = 5;

            int id_new_art = db_art.SaveArticle(art);
            return RedirectToAction("ViewArticle", new { id = id_new_art });
        }
        public ActionResult ViewArticle(string id)
        {
            BAIVIET art = db_art.GetArticle(Int32.Parse(id));
            ViewBag.PublishTime = String.Format("{0:dd/MM/yyyy}" , art.NgayTao) ;
            ViewBag.Content = Server.HtmlDecode(art.NoiDungHienThi);

            /////////////////
            //Phan nay se duoc bo sung khi co phan quyen
            /////////////////
            UnionDB db_union = (UnionDB)DAOFactory.getDAO("UnionDB");
            CSD union = db_union.GetUnion(5);
            ViewBag.UnionName = union.Ten;
            return View(art);
        }

        public ActionResult IndexPage()
        {
            ViewBag.ListArt = db_art.GetNewArticle(5);
            return View();
        }

        

    }
}
